package com.rsk.dao.extend;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class SysRoleExtend {

    public Map<String, Object> selectMenus(String roleName, String roleCode){
        // 拼接SQL语句
        StringBuilder sql = new StringBuilder("SELECT id,role_name,role_code FROM sys_roles Where is_del = 0");

        // 查询需要的参数，先存进Map
        StringBuilder paramSql = new StringBuilder();
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (roleName != null && !roleName.isEmpty()) {
            paramSql.append(" and role_name like :roleName");
            paramMap.put("roleName", "%" + roleName + "%");
        }
        if (roleCode != null && !roleCode.isEmpty()) {
            paramSql.append(" and role_code like :roleCode");
            paramMap.put("roleCode", "%" + roleCode + "%");
        }

        //排序
        StringBuilder orderSql = new StringBuilder();
        orderSql = orderSql.append(" order by sort");

        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("sql", sql.append(paramSql).append(orderSql));
        returnMap.put("paramMap", paramMap);
        return returnMap;
    }
}
